package example.file;

import java.io.File;

/**
 * Created by lenovo on 2016/11/4 0004.
 * File 类的 filename.compareTo (another filename) 方法来比较两个文件路径是否在同一个目录下
 */
public class ComparePath {
    public static void main(String[] args) {
        File file1 = new File("C:/File/demo1.txt");
        File file2 = new File("C:/java/demo1.txt");
        //file的compareTo方法，对比的是文件的路径是否相同
        if (file1.compareTo(file2) == 0) {
            System.out.println("文件路径一致！");
        } else {
            System.out.println("文件路径不一致！");
        }
    }
}
